//
//  MguideDetailModel.m
//  穷游项目
//
//  Created by 刘建镇 on 14-12-31.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//


#import "macro.h"
#import "MguideDetailModel.h"

@implementation MguideDetailModel

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc
{
    [_avatar release];
    [_descr release];
    [_photo release];
    [_username release];
    [_count release];
    [_title release];
    [super dealloc];
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.photo = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height/3)];
        [self addSubview:_photo];
        [_photo release];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width * 4/5+5, 5, self.frame.size.width*1/4, 30)];
        label.backgroundColor = [UIColor clearColor];
        label.text = @"个旅行地";
        label.textColor = [UIColor brownColor];
        label.font = [UIFont systemFontOfSize:13.0f];

        self.count = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width * 4/5, 5, self.frame.size.width*1/4, 30)];
//        _count.text = [NSString stringWithFormat:@"%@%@", _count.text, label.text];
        _count.backgroundColor = [UIColor clearColor];
        _count.textColor = [UIColor brownColor];
        _count.font = [UIFont systemFontOfSize:13.0f];
        [self addSubview:_count];
        [_count release];
        [self addSubview:label];
        [label release];
        
        //小头像
        self.avatar = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width/2 - self.frame.size.width / 14, self.frame.size.height/3 - self.frame.size.width / 14, self.frame.size.width/7, self.frame.size.width/7)];
        _avatar.layer.masksToBounds = YES;
        _avatar.layer.cornerRadius = self.frame.size.width / 14;
        [self addSubview:_avatar];
        [_avatar release];
        
        self.username = [[UILabel alloc] initWithFrame:CGRectMake(0, self.frame.size.height/3 + SCREEN_HEIGHT/22, self.frame.size.width, 20)];
        _username.textAlignment = NSTextAlignmentCenter;
        _username.textColor = [UIColor grayColor];
        _username.backgroundColor = [UIColor clearColor];
        [self addSubview:_username];
        [_username release];
        
        self.title = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width/8, self.frame.size.height * 1/3 + _avatar.frame.size.height, self.frame.size.width * 3/4, self.frame.size.height/8)];
        [_title setFont:[UIFont systemFontOfSize:20.0f]];
        _title.backgroundColor = [UIColor clearColor];
        _title.numberOfLines = 0;
        [self addSubview:_title];
        [_title release];

        self.descr = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width/8, self.frame.size.height*1/3 + _avatar.frame.size.height + _title.frame.size.height, self.frame.size.width * 3/4, SCREEN_HEIGHT)];
        _descr.backgroundColor = [UIColor clearColor];
        _descr.font = [UIFont systemFontOfSize:14.0f];
        _descr.numberOfLines = 0;
        _descr.adjustsFontSizeToFitWidth = YES;
        [self addSubview:_descr];
        [_descr release];
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];//layout->布局
    NSDictionary *dic  = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14.0f], NSFontAttributeName, nil];
    if (IOS_VERSION > 7.0) {
        CGRect rect = [self.descr.text boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        [self.descr setFrame:CGRectMake(self.descr.frame.origin.x, self.descr.frame.origin.y, self.descr.frame.size.width, rect.size.height)];
    } else {
        CGFloat height = [self.descr.text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(300, 1000)].height;
        [self.descr setFrame:CGRectMake(self.descr.frame.origin.x, self.descr.frame.origin.y, self.descr.frame.size.width, height)];
    }
}


@end
